// Code file original author: Martin Lapierre, http://devinstinct.com

using System;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using Microsoft.Practices.EnterpriseLibrary.Validation;

namespace EntLibContrib.Validation.Validators
{
    /// <summary>
    /// Provides pre-allocated, thread-safe validators.
    /// </summary>
    public static class DefaultValidators
    {
        #region Fields

        /// <summary>
        /// Validates that objects references are not null using, the default ruleset.
        /// </summary>
        public static readonly NotNullValidator NotNullValidator = new NotNullValidator();

        /// <summary>
        /// Validates that objects references are null using, the default ruleset.
        /// </summary>
        public static readonly NotNullValidator NullValidator = new NotNullValidator(true);

        /// <summary>
        /// Validates that strings are neither null nor empty, using the default ruleset.
        /// </summary>
        public static readonly AndCompositeValidator StringNotNullNorEmptyValidator = new AndCompositeValidator(DefaultValidators.NotNullValidator, new StringLengthValidator(0, RangeBoundaryType.Exclusive, int.MaxValue, RangeBoundaryType.Inclusive));

        /// <summary>
        /// Validates that collections are neither null nor empty, using the default ruleset.
        /// </summary>
        public static readonly AndCompositeValidator CollectionNotNullNorEmptyValidator = new AndCompositeValidator(DefaultValidators.NotNullValidator, new CollectionCountValidator(0, RangeBoundaryType.Exclusive, int.MaxValue, RangeBoundaryType.Inclusive));

        /// <summary>
        /// Validates that the value is Defined in the enum's values.
        /// </summary>
        public static readonly EnumDefinedValidator EnumDefinedValidator = new EnumDefinedValidator();

        /// <summary>
        /// Validates that the value is not Defined in the enum's values.
        /// </summary>
        public static readonly EnumDefinedValidator EnumNotDefinedValidator = new EnumDefinedValidator(true);

        #endregion Fields


        #region Classes

        /// <summary>
        /// Provides pre-allocated, thread-safe validators that are type-dependent.
        /// </summary>
        /// <remarks>Accessed thru <see cref="DefaultValidators"/>.</remarks>
        /// <typeparam name="T">The target type.</typeparam>
        public static class StronglyTypedValidators<T>
        {
            /// <summary>
            /// Validates that objects references are not null and that the objects are of the type-parameter type, using the default ruleset.
            /// </summary>
            public static readonly AndCompositeValidator NotNullTypeValidator = new AndCompositeValidator(DefaultValidators.NotNullValidator, new TypeValidator<T>());

            /// <summary>
            /// Validates that objects references are not null and that the objects are valid by themselves, using the default ruleset.
            /// </summary>
            public static readonly AndCompositeValidator NotNullObjectValidator = new AndCompositeValidator(DefaultValidators.NotNullValidator, new ObjectValidator<T>());
        }

        #endregion Classes
    }
}
